package com.spzx.product.controller;

import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.common.log.annotation.Log;
import com.spzx.common.log.enums.BusinessType;
import com.spzx.common.log.enums.OperatorType;
import com.spzx.common.security.utils.SecurityUtils;
import com.spzx.product.domain.Brand;
import com.spzx.product.service.IBrandService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 分类品牌 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2025-04-28
 */
@RestController
@RequestMapping("/brand")
public class BrandController extends BaseController {
    @Autowired
    private IBrandService brandService;
@Operation(summary="查询品牌列表")
//@RequiresPermissions("product:brand:list")
//@RequiresRoles("role:dev")
@Log(title="品牌管理",businessType = BusinessType.OTHER,operatorType = OperatorType.MANAGE)
    @GetMapping("/list")
    public TableDataInfo list(@Parameter(description="品牌名称") String name){
   startPage();
   List<Brand> list =brandService.selectBrandList(name);
   return getDataTable(list);
}
    @Operation(summary = "获取品牌详细信息")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id){
        Brand brand = brandService.getById(id);
        return AjaxResult.success(brand);
//        LambdaQueryWrapper<Brand> queryWrapper = new LambdaQueryWrapper<>();
//        queryWrapper.eq(Brand::getId,id);
//        queryWrapper.select(Brand::getId,Brand::getName,Brand::getLogo);
//        Brand brand = brandService.getOne(queryWrapper);
//        return AjaxResult.success(brand);
    }
    @Operation(summary = "新增品牌")
    @PostMapping
    public AjaxResult add(@Parameter(description = "品牌") @RequestBody Brand brand) {
    brandService.add(brand);
    return AjaxResult.success();
    }
    @Operation(summary = "修改品牌")
    @PutMapping
    public AjaxResult edit(@Parameter(description = "品牌") @RequestBody Brand brand) {
    brand.setUpdateBy(SecurityUtils.getUsername());
    brandService.updateById(brand);
    return AjaxResult.success();
    }

    @Operation(summary = "删除品牌")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(
            @Parameter(description = "品牌id列表", example = "[1,2]")
            @PathVariable List<Long> ids) {
    brandService.removeBatchByIds(ids);
    return AjaxResult.success();
    }

    @Operation(summary = "查询所有品牌列表")
    @GetMapping("/getBrandAll")
    public AjaxResult getBrandAll(){
    List<Brand> list =brandService.list();
    return  AjaxResult.success(list);
    }
}
